package com.kaifamiao.convert;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 1、LocalDate ==> LocalDateTime
 * 2、LocalTime ==> LocalDateTime
 * 3、LocalDateTime ==> LocalDate
 * 4、LocalDateTime ==> LocalTime
 */
public class DateTimeTest {

    public static void main(String[] args) {

        LocalDate date = LocalDate.of( 2020, 3, 1 );
        LocalTime time = LocalTime.of( 12, 12,12, 100200300 );

        // LocalDate ==> LocalDateTime
        LocalDateTime datetime = date.atTime( time );
        System.out.println( datetime );

        datetime = date.atTime( 14, 20 );
        System.out.println( datetime );

        datetime = date.atTime( 14, 20 , 50 );
        System.out.println( datetime );

        datetime = date.atTime( 14, 20 , 50, 100200300 );
        System.out.println( datetime );

        // LocalTime ==> LocalDateTime
        datetime = time.atDate( date );
        System.out.println( datetime );


        datetime = LocalDateTime.now();

        // LocalDateTime ==> LocalDate
        date = datetime.toLocalDate();
        System.out.println( date );

        // LocalDateTime ==> LocalTime
        time = datetime.toLocalTime();
        System.out.println( time );


    }

}
